import re
import json

global_variable = re.compile(r'\{\$(\w+)?\}')

def matching(key,value):
    key = key if isinstance(key,str) else json.dumps(key,ensure_ascii=False)
    while global_variable.search(key):
        content = global_variable.search(key)
        replaced_key = global_variable.search(key).group(0)
        key = key.replace(replaced_key,value[global_variable.search(key).group(1)])
    return key